package com.example.xiaoming.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * 版权：wxj公司 版权所有
 *
 * @author ：wxj
 * 版本：1.01080478
 * 创建日期：2021/7/2 if
 * 包名：com.example.xiaoming.view
 * 类名：xiaoming
 * 加密：switch
 * 描述：
 */
public class DrawView extends View {

    private Paint paint;
    private float x;
    private float y;
    private float x1;
    private float y1;
    private int mHeight;
    private int mWidth;


    public DrawView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setColor(0xff000000);
        paint.setStrokeWidth(3);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        mWidth = MeasureSpec.getSize(widthMeasureSpec);
        mHeight = MeasureSpec.getSize(heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawLine(x, y, x1, y1, paint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN | event.getAction() == MotionEvent.ACTION_MOVE) {
            x = x1;
            y = y1;
            x1 = event.getX();
            y1 = event.getY();
            Log.e("ddda", x + "" + y);
            invalidate();
            return true;
        }
        return super.onTouchEvent(event);
    }
}
